import java.util.LinkedList;
import java.util.Queue;

public class Demo3 {
    public static void main(String[] args) {

        for (int i = 10000000; i >= 197; i--) {
            String str = i + "";
            int len = str.length(); // 计算出是几位数
            int num = i;
            int[] arr = new int[len];
            int count = len - 1;
            while (num > 0) {
                arr[count--] = num % 10;
                num /= 10;
            }
            Queue<Integer> q = new LinkedList<>();
            for (int x : arr) {
                q.offer(x);
            }

            while (true) {
                int sum = 0;
                for (int x : q) {
                    sum += x;
                }
                q.poll();
                if (sum == i) {
                    System.out.println(sum);
                    return;
                } else if (sum > i) {
                    break;
                }
                q.offer(sum);
            }
        }
    }
}
